var webPath = "";
var webPath1 = "";
$(document).ready(function(){
	webPath = $("#webPath").val();
	webPath1 = $("#webPath1").val();
	var msg = $("#message").val();
	if(msg != ""){
		alert(msg);
	}
	
	$("#submit_btn").click(submit);
});
function changeValidateCode(){
	var timenow = new Date().getTime();
	$("#vImg").attr("src", webPath1+"/rand?d="+timenow);
}
function submit(){
	var msgId   = $("#id_msgId").val();
	var author  = $("#id_author").val();
	var idcard  = $("#id_idcard").val();
	var phone   = $("#id_phone").val();
	var email   = $("#id_email").val();
	var content = $("#id_content").val();
	var vcode   = $("#id_vcode").val();
	
	if(string.trim(author) == ""){
		alert("请输入姓名！");
		$("#id_author").select();
		return false;
	}
	if(string.trim(idcard) == ""){
		alert("请输入身份证号码！");
		$("#id_idcard").select();
		return false;
	}else{
		if(!string.isIDcard(idcard)){
			alert("身份证格式不正确！");
			$("#id_idcard").select();
			return false;
		}
	}
	if(string.trim(phone) != "" && !string.isPhone(phone)){
		alert("手机号码格式不正确！");
		return false;
	}
	if(string.trim(email) != "" && !string.isEmail(email)){
		alert("电子邮箱格式不正确！");
		return false;
	}
	if(string.trim(content).length < 4){
		alert("输入的内容过短，有灌水嫌疑！");
		return false;
	}
	if(string.trim(vcode).length < 4){
		alert("验证码输入有误！");
		return false;
	}
	
	var data = {"msgId": msgId, "commentAuthor": author, "authorIdcard": idcard, "authorPhone": phone,
			"authorEmail": email, "commentContent": content, "vCode": vcode};
	
	$.ajax({
		type: "POST",
		cache: false,
		dataType: "json",
		url: webPath+"/comment/add",
		data: data,
		success: function(msg){
			$("#id_author").val("");
			$("#id_idcard").val("");
			$("#id_phone").val("");
			$("#id_email").val("");
			$("#id_content").val("");
			$("#id_vcode").val("");
			changeValidateCode();
			alert(msg);
		}
	});
}